#include "ws2812b_core.h"

/*
 *  控制方向
 */
#if 0
#define DIRF    0x1F
#define DIRB    0
#else
#define DIRF    0
#define DIRB    0xFF
#endif

void example_3(COLOR *buf, uint16_t buf_len, uint16_t *stept)
{
    uint16_t lstept = *stept;
    uint8_t j=0;

    switch(lstept)
    {
        case 0:
            for(uint8_t i=0; i<buf_len; i++){
                switch (j)
                {
                case 0:
                    buf[i].r = DIRF+DIRB;
                    buf[i].g = 0;
                    buf[i].b = 0;
                    j++;
                    break;
                case 1:
                    buf[i].r = 0;
                    buf[i].g = DIRF+DIRB;
                    buf[i].b = 0;
                    j++;
                    break;
                case 2:
                    buf[i].r = 0;
                    buf[i].g = 0;
                    buf[i].b = DIRF+DIRB;
                    j=0;
                    break;
                default:
                    break;
                }
            }
        break;
        
        case 1:
            for(uint8_t i=0; i<buf_len; i++){
                switch (j)
                {
                case 0:
                    buf[i].r = 0;
                    buf[i].g = DIRF;
                    buf[i].b = DIRB;
                    j++;
                    break;
                case 1:
                    buf[i].r = DIRB;
                    buf[i].g = 0;
                    buf[i].b = DIRF;
                    j++;
                    break;
                case 2:
                    buf[i].r = DIRF;
                    buf[i].g = DIRB;
                    buf[i].b = 0;
                    j=0;
                    break;
                default:
                    break;
                }
            }
        break;

        case 2:
            for(uint8_t i=0; i<buf_len; i++){
                switch (j)
                {
                case 0:
                    buf[i].r = 0;
                    buf[i].g = DIRB;
                    buf[i].b = DIRF;
                    j++;
                    break;
                case 1:
                    buf[i].r = DIRF;
                    buf[i].g = 0;
                    buf[i].b = DIRB;
                    j++;
                    break;
                case 2:
                    buf[i].r = DIRB;
                    buf[i].g = DIRF;
                    buf[i].b = 0;
                    j=0;
                    break;
                default:
                    break;
                }
            }
        break;
                
        default:
        break;
    }
        

    if(*stept < 2){
        (*stept)++;
    }
    else{
        (*stept)=0;
    }
}


